import { Login } from "@/api/interface";
import http from "@/api";
import { ServiceResult } from "@/core/fetch/handle";
import { Menu } from "@/typings/global";

/**
 * @name 登录模块
 */
// 用户登录
export const loginApi = (params: Login.ReqLoginForm) => {
  const method = http.Post<Login.ResLogin>("/auth/login", params);

  method.meta = {
    authRole: "login"
  };
  return method;
};

// 获取菜单列表
export const getAuthMenuListApi = () => {
  return http.Get<ServiceResult<Menu.MenuOptions[]>>("/menu/user/list");
  // 如果想让菜单变为本地数据，注释上一行代码，并引入本地 authMenuList.json 数据
  // return authMenuList;
};

// 获取按钮权限
export const getAuthButtonListApi = () => {
  return http.Get<ServiceResult<string[]>>(`/auth/permission`);
};

// 用户退出登录
export const logoutApi = () => {
  return http.Post(`/auth/logout`);
};
